// Copyright 2012 Google Inc. All Rights Reserved.

package com.google.appengine.syncserver.entities;

/**
 * Cache for the client update request pages. We store all client pages in one
 * consolidated Preferences object.
 */
public class RequestPageCache extends Preferences {

  public static final String SEPARATOR = "|";

  private static String getNamespacedPreferenceName(long clientId, String preferencesName) {
    return clientId + SEPARATOR + preferencesName;
  }

  public RequestPageCache(String username, String preferencesName, long clientId) throws Exception {
    super(username, getNamespacedPreferenceName(clientId, preferencesName),
        EntityKeyFactory.PreferencesEntityKind.REQUEST_PAGE_CACHE);
  }

  /**
   * Clear the page from the cache.
   */
  public void clearPage() throws Exception {
    clear();
    removeMetadata();
    commit();
  }
}
